package com.hitplane.elements.state 
{
	
	import com.hitplane.core.Bullet;
	import com.hitplane.interfaces.IState;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	/**
	 * @描述
	 * @作者		rrDog
	 * @版本		version 1.0
	 * @创建日期	$date
	 */
	public class BulletHitState implements IState
	{
		private var _bullet:Bullet;
		private var _stateType:String = "hit_state";
		
		public const ANIMAL_END:String = "hit_animal_end";
		
		public function BulletHitState(bullet:Bullet) 
		{
			_bullet = bullet;
		}
		
		/* INTERFACE com.hitplane.interfaces.IState */
		
		public function startState():void 
		{
			_bullet.setShowState(_stateType);
			
			//注：TimelineWatch可以比较好的解决时间轴代码的问题
			var hitMc:MovieClip=_bullet.stateArr[_stateType] as MovieClip;
			hitMc.addFrameScript(hitMc.totalFrames-1,function():void{
				hitMc.dispatchEvent(new Event(ANIMAL_END,true));
				hitMc.addFrameScript(hitMc.totalFrames-1,null);
			});
		}
		
		public function keepState():void 
		{
		}
		
		public function stopState():void 
		{
			var hitMc:MovieClip=_bullet.stateArr[_stateType] as MovieClip;
			hitMc.gotoAndStop(1);
		}
		
		public function get stateType():String 
		{
			return _stateType;
		}
		
		public function set stateType(value:String):void 
		{
			_stateType=value;
		}
		
	}

}